Repository navigation
[PR] Consistently apply sandbox CSP + nosniff to blog asset responses, blocking same-origin SVG script execution in the panel | 博客资产响应统一加 sandbox CSP + nosniff,堵住面板同源 SVG 执行脚本 - #4970
Merged
Conversation
Contributor
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.6489-pr.4970.0e2ed75This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr4970.tgz
npm install -g packageInstall instructions are refreshed on each push. |
Contributor
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.884-master.51c9861 # this exact build
npm install -g billion-context@master # always the newest merged build
|
ranxianglei
pushed a commit
that referenced
this pull request
Oct 27, 2026
Follow-up merge after master advanced past c499b14 mid-resolution (#4969/#4970/#4972/#4971 blog+billing, #4544 event-loop-yield, #4678 mysql-v8-dedup, #4782 dsh-goal-subfork). Conflicts: - src/server/prepare-responses.ts: import hunk unioned again - kept this branch's fold-reconcile import line (superset of master's: adds noteBiliToolSurface/outboundBiliSurface); master's yieldToEventLoop lines from #4528 landed in all four prepare files untouched. - tests/golden/storage-render/{anthropic,chat,google,responses}.json: regenerated from the merged tree via scripts/update-storage-render-goldens.ts; output byte-identical to the previous round's regeneration (master's new commits did not change these golden conversations' outbound wire or persisted state) and differing from master only by this branch's image-rescale armed-state latch digests. Verification: no conflict markers remain; targeted suites green (golden-storage-render + fold-reconcile + issue3400-image-rescale = 109/109); typecheck clean. Full-suite verdict deferred to CI on the pushed head.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(ai: zhipuai-lb/glm-5.3)
Fixes #4958
问题
GET /__bili/blog-assets/<rel>把博客图片直接从面板同源服务。其中 SVG 以image/svg+xml类型响应,且此前没有任何 sandbox/nosniff 头。SVG 是主动内容:用户把浏览器直接导航到该 URL 时,SVG 内嵌的<script>会在面板 origin 上执行——而这个 origin 同时挂着配置编辑器(PUT /__bili/config,含各 provider 的 API key),脚本可以读取并外传。信任模型原本不一致:博客 markdown 按「不可信」处理(escape-first 渲染),而资产字节按「可信」直出。#4906 之前资产只能来自随包文件;#4906 之后远端 GitHub master 字节也会直出,一次坏合并(外部 PR 里一个看似无害的
figures/*.svg)= 所有已升级用户面板上的存储型 XSS。根因
src/web/blogfeed.tshandleBlogAssetGet的三处writeHead都只带content-type+cache-control。ASSET_TYPES含.svg → image/svg+xml。修法
ASSET_SECURITY_HEADERS = { "content-security-policy": "sandbox", "x-content-type-options": "nosniff" },应用到该路由的每一处响应:远端 overlay 200、磁盘兜底 200、404。content-type/cache-control/ 响应字节保持逐字节不变;.svg保留在ASSET_TYPES(页内<img>引用不受 sandbox 头影响——src/web/markdown.ts只允许https?://或/__bili/blog-assets/的 img src,而<img>方式加载的 SVG 本身不执行脚本,sandbox 只约束把资产当文档直接导航的场景)。测试
tests/web-blogfeed.test.ts新增:<script>的 SVG fixture)与磁盘兜底路径的响应都带content-security-policy: sandbox+x-content-type-options: nosniff,且 content-type 与响应字节不变;资产路由 404 也带这对头。handleBlogGet(博客 JSON feed 路由)不获得这对头。tests/web-routing.test.ts:真服务器断言面板 HTML 路由(GET /__bili/)不获得这对头(改动方向钉死:头只加在资产路由)。本地验证:
node --import tsx --test tests/web-blogfeed.test.ts10/10 通过;tests/web-routing.test.ts8/8 通过;tests/web-blog-refresh.test.ts17/17 通过(相邻面回归);npm run typecheck干净。完整套件以后续 CItestlanes 为准。